class Txt2man < Formula
  desc "Converts flat ASCII text to man page format"
  homepage "https://github.com/mvertes/txt2man/"
  url "https://github.com/mvertes/txt2man/archive/refs/tags/txt2man-1.7.1.tar.gz"
  sha256 "4d9b1bfa2b7a5265b4e5cb3aebc1078323b029aa961b6836d8f96aba6a9e434d"
  license "GPL-2.0-or-later"

  livecheck do
    url :stable
    regex(/^(?:txt2man[._-])?v?(\d+(?:\.\d+)+)$/i)
  end

  no_autobump! because: :requires_manual_review

  bottle do
    rebuild 1
    sha256 cellar: :any_skip_relocation, all: "fc8be081e702c9f38869232afb35214fc78bc7765ba03a508f140452ce6fe606"
  end

  depends_on "gawk"

  def install
    system "make", "install", "prefix=#{prefix}"
  end

  test do
    (testpath/"foo.txt").write "foo"
    (testpath/"foo.1").write Utils.safe_popen_read(bin/"txt2man", "-d", "17 Dec 2022", testpath/"foo.txt")

    expected = <<~EOS
      .\\" Text automatically generated by txt2man
      .TH untitled  "17 Dec 2022" "" ""
      .RS
      foo
    EOS

    assert_equal expected, (testpath/"foo.1").read
  end
end
